<template>
  <div>
    <FormPanel
      ref="areaMaintain"
      :list="initForm"
      :cols="3"
      :labelWidth="90"
      :isSubmitBtn="false"
      @formChange="formChangeHandle"
    />
    <!-- table -->
    <FilterTable
      height='300'
      ref="table"
      :columns="columns"
      :dataSource="dataSource"
      :isSelectColumn="isSelectColumn"
      :params="flterValue"
      :datakey="'records'"
      :onColumnsChange="columns => this.columns = columns"
    >
      <template slot="controls">
        <el-button size="small" type="primary" icon="el-icon-plus" @click="dealerHandle">选择经销商</el-button>
      </template>
    </FilterTable>
    <div class="dialogBottmView">
      <el-button @click="closeDialog">取 消</el-button>
      <el-button @click="saveDialog"  type="primary">保 存</el-button>
    </div>
    <!-- 经销商弹窗 -->
    <BaseDialog
      title="经销商查询"
      :visible.sync="visibleDealer"
      width="1000px"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <dealer-madal  ref='addDialogRef'  @close="closeDealer" />
    </BaseDialog>
    <!-- 经销商弹窗 -->
    <BaseDialog
      title="人员选择"
      :visible.sync="visiblePersonnel"
      width="1000px"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <personnelMadal   @close="closePersonnel" />
    </BaseDialog>
  </div>
</template>
<script>
import personnelMadal from '../../../customerManage/clue/areaBossOperation/personnel'
import dealerMadal from '../../../customerManage/clue/areaBossOperation/dealerDialog';
import { dictionary } from '@/utils/dictMixin';
export default {
  components: {
    dealerMadal,personnelMadal
  },
  props:{
    value:{
      type:Object,
      default:{}
    }
  },
  mixins: [dictionary],
  data() {
    return {
      visiblePersonnel: false,
      visibleDealer: false,
      dataSource:[],
      isSelectColumn: false,
      initForm: this.initFormFun(),
      flterValue: {}, //参数
      columns: this.creatHeader()
    };
  },
  mounted() {
    consolo.lgo(this.value) //父页面传过来数据
  },
  methods: {
    //搜索数据
    initFormFun() {
      return [
         {
          type: 'SELECT',
          label: '事业部',
          fieldName: 'field1',
          placeholder: '请选择',
          initialValue: '',
          itemList: this.createDictList('1008'),
          rules: [
            {
              required: true,
              message: '必填',
              trigger: 'change'
            }
          ]
        },
        {
          type: 'SELECT',
          label: '办事处',
          fieldName: 'field2',
          placeholder: '请选择',
          initialValue: '',
          itemList: this.createDictList('1008'),
          rules: [
            {
              required: true,
              message: '必填',
              trigger: 'change'
            }
          ]
        }, {
          type: 'INPUT',
          label: '区域经理代码',
          fieldName: 'dealer',
          placeholder: '请选择',
          initialValue: '',
          unitRender: () => {
            return <el-button slot="append" icon="el-icon-search" onClick={() => this.personnelHandle()}></el-button>;
          }
        },{
          type: 'INPUT',
          label: '区域经理姓名',
          fieldName: 'field4',
          placeholder: '请输入',
          disabled: true,
          initialValue: ''
        },
        {
          type: 'SELECT',
          label: '办事处',
          fieldName: 'field5',
          placeholder: '请选择',
          initialValue: '',
          itemList: this.createDictList('1008')
        },{
          type: 'INPUT',
          label: '手机',
          fieldName: 'field6',
          placeholder: '请输入',
          disabled: true,
          initialValue: ''
        },{
          type: 'INPUT',
          label: '身份证号',
          fieldName: 'field7',
          placeholder: '请输入',
          disabled: true,
          initialValue: ''
        },
        {
          type: 'SELECT',
          label: '状态',
          fieldName: 'field8',
          placeholder: '请选择',
          initialValue: '',
          itemList: this.createDictList('1008')
        }
      ];
    },
    //搜索获取数据
    changeHandle(val) {
      this.flterValue = val;
      console.log(val);
    },
    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <el-button size="mini" type="text" >删除</el-button>
              </div>
            );
          }
        },
        { title: '公司全称', dataIndex: 'field0', sorter: true },
        { title: '经销商代码', dataIndex: 'field1', sorter: true },
        { title: '经销商简称', dataIndex: 'field2', sorter: true },
        { title: '经销商类型', dataIndex: 'field3', sorter: true },
        { title: '经销商级别', dataIndex: 'field4', sorter: true },
        { title: '事业部', dataIndex: 'field5', sorter: true },
        { title: '省份', dataIndex: 'field6', sorter: true },
        { title: '城市', dataIndex: 'field7', sorter: true },
        { title: '县区', dataIndex: 'field8', sorter: true }
      ];
    },
    // 人员 打开窗口
    personnelHandle() {
      this.visiblePersonnel = true;
    },
    // 人员关闭窗口 -返回数据
    closePersonnel(data) {
      this.initForm[2].initialValue='人员'
      //返回数据逻辑自己写
      this.visiblePersonnel = data.visible; //关闭弹窗
    },
    // 经销商打开窗口 -传数据
    dealerHandle() {
      this.visibleDealer = true;
    },
    // 经销商关闭窗口 -返回数据
    closeDealer(data) {
      this.dataSource=[
        {field0:'吉林公司',field1:'DS2345768',field2:'吉林',field3:'A',field6:'吉林省',field7:'长春市',field8:'南关区'}
      ]
      //返回数据逻辑自己写
      this.visibleDealer = data.visible; //关闭弹窗
    },
    formChangeHandle(data){
      console.log(data)
      this.$emit('close', {type:'refresh',});
    },
    //保存
    saveDialog(){
      this.$refs.areaMaintain.SUBMIT_FORM()
    },
    //取消操作
    closeDialog() {
      this.$emit('close', { visible: false });
    }
  }
};
</script>

<style lang="less" scoped>
</style>
